<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      //终止条件 start==s.length

      var restoreIpAddresses = function (s) {
        const res = []
        function backTracking(path, start) {
          if (path.length > 4) return
          if (start == s.length && path.length == 4) {
            return res.push([...path])
          }
          for (let i = start; i < s.length; i++) {
            let str = s.slice(start, i + 1)
            if (Number(str) < 0 || Number(str) > 255) break
            if (str.length > 1 && str[0] == '0') break
            path.push(str)
            backTracking(path, i + 1)
            path.pop()
          }
        }
        backTracking([], 0)
        return res
      }
    </script>
  </body>
</html>
